Packages and Data

library(GISTools)
## Loading required package: maptools
## Loading required package: sp
## Checking rgeos availability: TRUE
## Loading required package: RColorBrewer
## Loading required package: MASS
## Loading required package: rgeos
## rgeos version: 0.3-25, (SVN revision 555)
##  GEOS runtime version: 3.6.1-CAPI-1.10.1 r0 
##  Linking to sp version: 1.2-5 
##  Polygon checking: TRUE
library(tidyverse)
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag():    dplyr, stats
## select(): dplyr, MASS
library(broom)
library(rgeos)
data(georgia)
ls()
## [1] "georgia"       "georgia.polys" "georgia2"

Georgia Maps

plot(georgia)

plot(georgia, 
     col = "red", 
     bg = "wheat")

class(georgia)
## [1] "SpatialPolygonsDataFrame"
## attr(,"package")
## [1] "sp"
georgia_outline <- gUnaryUnion(georgia, 
                               id = NULL)
plot(georgia, 
     asp = 1, 
     col = "red", 
     bg = "wheat", 
     lty = 2, 
     border = "blue")
plot(georgia_outline, 
     asp = 1, 
     lwd = 3, 
     add = TRUE)
title(main = "The State of Georgia",
      font.main = 2,
      cex.main = 1.5, 
      sub = "and its counties",
      font.sub = 3,
      col.sub = "blue")

par(mfrow = c(1, 2),
    mar = c(2, 0, 3, 0))
plot(georgia, 
     col = "red", 
     bg = "wheat")
title("georgia")
plot(georgia2, 
     col = "orange",
     bg = "lightyellow")
title("georgia2")

par(mfrow = c(1,1))

georgia

str(georgia@data)
## 'data.frame':    159 obs. of  14 variables:
##  $ Latitude: num  31.8 31.3 31.6 31.3 33.1 ...
##  $ Longitud: num  -82.3 -82.9 -82.5 -84.5 -83.3 ...
##  $ TotPop90: num  15744 6213 9566 3615 39530 ...
##  $ PctRural: num  75.6 100 61.7 100 42.7 100 64.6 75.2 47 66.2 ...
##  $ PctBach : num  8.2 6.4 6.6 9.4 13.3 6.4 9.2 9 7.6 7.5 ...
##  $ PctEld  : num  11.43 11.77 11.11 13.17 8.64 ...
##  $ PctFB   : num  0.64 1.58 0.27 0.11 1.43 0.34 0.92 0.82 0.33 1.19 ...
##  $ PctPov  : num  19.9 26 24.1 24.8 17.5 15.1 14.7 10.7 22 19.3 ...
##  $ PctBlack: num  20.8 26.9 15.4 51.7 42.4 ...
##  $ X       : num  941397 895553 930946 745399 849431 ...
##  $ Y       : num  3521764 3471916 3502787 3474765 3665553 ...
##  $ ID      : int  13001 13003 13005 13007 13009 13011 13013 13015 13017 13019 ...
##  $ Name    : chr  "Appling" "Atkinson" "Bacon" "Baker" ...
##  $ MedInc  : num  32152 27657 29342 29610 36414 ...
georgia$Name
##   [1] "Appling"       "Atkinson"      "Bacon"         "Baker"        
##   [5] "Baldwin"       "Banks"         "Barrow"        "Bartow"       
##   [9] "Ben Hill"      "Berrien"       "Bibb"          "Bleckley"     
##  [13] "Brantley"      "Brooks"        "Bryan"         "Bulloch"      
##  [17] "Burke"         "Butts"         "Calhoun"       "Camden"       
##  [21] "Candler"       "Carroll"       "Catoosa"       "Charlton"     
##  [25] "Chatham"       "Chattahoochee" "Chattooga"     "Cherokee"     
##  [29] "Clarke"        "Clay"          "Clayton"       "Clinch"       
##  [33] "Cobb"          "Coffee"        "Colquitt"      "Columbia"     
##  [37] "Cook"          "Coweta"        "Crawford"      "Crisp"        
##  [41] "Dade"          "Dawson"        "Decatur"       "DeKalb"       
##  [45] "Dodge"         "Dooly"         "Dougherty"     "Douglas"      
##  [49] "Early"         "Echols"        "Effingham"     "Elbert"       
##  [53] "Emanuel"       "Evans"         "Fannin"        "Fayette"      
##  [57] "Floyd"         "Forsyth"       "Franklin"      "Fulton"       
##  [61] "Gilmer"        "Glascock"      "Glynn"         "Gordon"       
##  [65] "Grady"         "Greene"        "Gwinnett"      "Habersham"    
##  [69] "Hall"          "Hancock"       "Haralson"      "Harris"       
##  [73] "Hart"          "Heard"         "Henry"         "Houston"      
##  [77] "Irwin"         "Jackson"       "Jasper"        "Jeff Davis"   
##  [81] "Jefferson"     "Jenkins"       "Johnson"       "Jones"        
##  [85] "Lamar"         "Lanier"        "Laurens"       "Lee"          
##  [89] "Liberty"       "Lincoln"       "Long"          "Lowndes"      
##  [93] "Lumpkin"       "McDuffie"      "McIntosh"      "Macon"        
##  [97] "Madison"       "Marion"        "Meriwether"    "Miller"       
## [101] "Mitchell"      "Monroe"        "Montgomery"    "Morgan"       
## [105] "Murray"        "Muscogee"      "Newton"        "Oconee"       
## [109] "Oglethorpe"    "Paulding"      "Peach"         "Pickens"      
## [113] "Pierce"        "Pike"          "Polk"          "Pulaski"      
## [117] "Putnam"        "Quitman"       "Rabun"         "Randolph"     
## [121] "Richmond"      "Rockdale"      "Schley"        "Screven"      
## [125] "Seminole"      "Spalding"      "Stephens"      "Stewart"      
## [129] "Sumter"        "Talbot"        "Taliaferro"    "Tattnall"     
## [133] "Taylor"        "Telfair"       "Terrell"       "Thomas"       
## [137] "Tift"          "Toombs"        "Towns"         "Treutlen"     
## [141] "Troup"         "Turner"        "Twiggs"        "Union"        
## [145] "Upson"         "Walker"        "Walton"        "Ware"         
## [149] "Warren"        "Washington"    "Wayne"         "Webster"      
## [153] "Wheeler"       "White"         "Whitfield"     "Wilcox"       
## [157] "Wilkes"        "Wilkinson"     "Worth"
georgia$id <- as.character(0:(nrow(georgia@data) - 1))
georgia_df <- georgia %>%
  tidy()
## Regions defined for each Polygons
str(georgia_df)
## 'data.frame':    14909 obs. of  7 variables:
##  $ long : num  -82.2 -82.2 -82.2 -82.2 -82.2 ...
##  $ lat  : num  31.9 31.9 31.9 31.9 31.9 ...
##  $ order: int  1 2 3 4 5 6 7 8 9 10 ...
##  $ hole : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
##  $ piece: Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
##  $ group: Factor w/ 162 levels "0.1","1.1","2.1",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ id   : chr  "0" "0" "0" "0" ...
table(sort(georgia_df$id))
## 
##   0   1  10 100 101 102 103 104 105 106 107 108 109  11 110 111 112 113 
## 125  99 107  96  51  93  85 138 105 100 111 128  25  26  62  40 187  64 
## 114 115 116 117 118 119  12 120 121 122 123 124 125 126 127 128 129  13 
##  24  48  92  54 163  64 163 115  57  35 218  82  86  47  83  86 107 157 
## 130 131 132 133 134 135 136 137 138 139  14 140 141 142 143 144 145 146 
##  99 114 147 208  73  34  47  91  65  91 287  32  57 136 128  87  27  67 
## 147 148 149  15 150 151 152 153 154 155 156 157 158  16  17  18  19   2 
##  94 123 189 190 171  48 165 113 121 116 137 121 102 136  77  93 227  53 
##  20  21  22  23  24  25  26  27  28  29   3  30  31  32  33  34  35  36 
##  37  56  30 256 180  96  32  47  68  68 124  73  64  59  92  67  87 115 
##  37  38  39   4  40  41  42  43  44  45  46  47  48  49   5  50  51  52 
## 108 117  43 116  14  56  50  54  91  67  48  44  89  58  57 205 125 133 
##  53  54  55  56  57  58  59   6  60  61  62  63  64  65  66  67  68  69 
##  56  73 111  71  72  54 150  88  97  64 138  75  25 105  74 125  95 125 
##   7  70  71  72  73  74  75  76  77  78  79   8  80  81  82  83  84  85 
##  48  17  73  57  22 119 155  60  94  72  97  69 109  26  58  42  17  54 
##  86  87  88  89   9  90  91  92  93  94  95  96  97  98  99 
##  72  76 221  99 160 150 176 106 117 143  81 126  74  82  24
georgia_df <- left_join(georgia@data, georgia_df, 
                        by = c("id" = "id"))
str(georgia_df)
## 'data.frame':    14909 obs. of  21 variables:
##  $ Latitude: num  31.8 31.8 31.8 31.8 31.8 ...
##  $ Longitud: num  -82.3 -82.3 -82.3 -82.3 -82.3 ...
##  $ TotPop90: num  15744 15744 15744 15744 15744 ...
##  $ PctRural: num  75.6 75.6 75.6 75.6 75.6 75.6 75.6 75.6 75.6 75.6 ...
##  $ PctBach : num  8.2 8.2 8.2 8.2 8.2 8.2 8.2 8.2 8.2 8.2 ...
##  $ PctEld  : num  11.4 11.4 11.4 11.4 11.4 ...
##  $ PctFB   : num  0.64 0.64 0.64 0.64 0.64 0.64 0.64 0.64 0.64 0.64 ...
##  $ PctPov  : num  19.9 19.9 19.9 19.9 19.9 19.9 19.9 19.9 19.9 19.9 ...
##  $ PctBlack: num  20.8 20.8 20.8 20.8 20.8 ...
##  $ X       : num  941397 941397 941397 941397 941397 ...
##  $ Y       : num  3521764 3521764 3521764 3521764 3521764 ...
##  $ ID      : int  13001 13001 13001 13001 13001 13001 13001 13001 13001 13001 ...
##  $ Name    : chr  "Appling" "Appling" "Appling" "Appling" ...
##  $ MedInc  : num  32152 32152 32152 32152 32152 ...
##  $ id      : chr  "0" "0" "0" "0" ...
##  $ long    : num  -82.2 -82.2 -82.2 -82.2 -82.2 ...
##  $ lat     : num  31.9 31.9 31.9 31.9 31.9 ...
##  $ order   : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ hole    : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
##  $ piece   : Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
##  $ group   : Factor w/ 162 levels "0.1","1.1","2.1",..: 1 1 1 1 1 1 1 1 1 1 ...
ggplot(georgia_df, aes(x = long, y = lat, group = group)) +
  geom_polygon(fill = "white", colour = "black") +
  geom_text(aes(x = Longitud, y = Latitude, label = Name), size = 1) +
  coord_map()

County Names

Lat <- data.frame(georgia)[, 1] #> georgia$Latitude
Lon <- data.frame(georgia)[, 2] #> georgia$Longitud
Names <- data.frame(georgia)[, 13] #> georgia$Name
plot(georgia, 
     col = NA)
text(Lon, Lat, 
     labels = Names, 
     cex = 0.5) #> Better than `pointLabel`

# pl <- pointLabel(Lon, Lat, Names, offset = 0, cex = 0.5)

Subregion

counties <- c("Jefferson", "Jenkins", "Johnson", "Washington", "Glascock", "Emanuel", "Candler", "Bulloch", "Screven", "Richmond", "Burke")
counties_idx <- which(georgia$Name %in% counties)
counties_idx
##  [1]  16  17  21  53  62  81  82  83 121 124 150
georgia_sub <- georgia[counties_idx, ]
plot(georgia_sub, 
     col = "gold1", 
     border = "grey")
plot(georgia_outline, 
     add = TRUE, 
     lwd = 2)
text(Lon[counties_idx], Lat[counties_idx], 
     labels = Names[counties_idx], 
     cex = 1)

plot(georgia, 
     border = "grey", 
     lwd = 0.5)
plot(georgia_sub, 
     col = "lightblue", 
     add = TRUE)
plot(georgia_outline,
     lwd = 2, 
     add = TRUE)
title("Georgia with a subset of counties")

Open Street Map

# install.packages("OpenStreetMap", dependencies = TRUE)
library(OpenStreetMap)
ul <- as.vector(cbind(bbox(georgia_sub)[2, 2], 
                      bbox(georgia_sub)[1, 1]))
lr <- as.vector(cbind(bbox(georgia_sub)[2, 1], 
                      bbox(georgia_sub)[1, 2]))
MyMap <- openmap(upperLeft = ul, 
                 lowerRight = lr, 
                 zoom = 9, 
                 type = 'osm') #> Try various `maptype`
plot(MyMap, removeMargin = FALSE)
plot(spTransform(georgia_sub, 
                 osm()), 
     lwd = 2, 
     add = TRUE)

RgoogleMaps, PBSmapping

# install.packages(c("RgoogleMaps", "PBSmapping"))
library(RgoogleMaps)
library(PBSmapping)
## 
## -----------------------------------------------------------
## PBS Mapping 2.70.4 -- Copyright (C) 2003-2017 Fisheries and Oceans Canada
## 
## PBS Mapping comes with ABSOLUTELY NO WARRANTY;
## for details see the file COPYING.
## This is free software, and you are welcome to redistribute
## it under certain conditions, as outlined in the above file.
## 
## A complete user guide 'PBSmapping-UG.pdf' is located at 
## /Library/Frameworks/R.framework/Versions/3.4/Resources/library/PBSmapping/doc/PBSmapping-UG.pdf
## 
## Packaged on 2017-06-28
## Pacific Biological Station, Nanaimo
## 
## All available PBS packages can be found at
## https://github.com/pbs-software
## 
## To see demos, type '.PBSfigs()'.
## -----------------------------------------------------------
shp <- SpatialPolygons2PolySet(georgia_sub)
bb <- qbbox(lat = shp[, "Y"], lon = shp[, "X"])
MyMap <- GetMap.bbox(bb$lonR, bb$latR, destfile = "DC.jpg")
PlotPolysOnStaticMap(MyMap,
                     asp = 1,
                     shp, 
                     lwd = 2, 
                     col = rgb(0.25, 0.25, 0.25, 0.025),
                     add = FALSE)

Mapping Polygons and Attributes

Newhaven

rm(list = ls())
data(newhaven)
vacant_shades <- auto.shading(blocks$P_VACANT)
vacant_shades
## $breaks
##  20%  40%  60%  80% 
##  5.4  7.6 10.0 13.0 
## 
## $cols
## [1] "#FEE5D9" "#FCAE91" "#FB6A4A" "#DE2D26" "#A50F15"
## 
## attr(,"class")
## [1] "shading"
choropleth(blocks, 
           v = blocks$P_VACANT)
choro.legend(533000, 161000, 
             sh = vacant_shades)

vacant_shades <- auto.shading(blocks$P_VACANT, 
                              n = 7)
choropleth(blocks, 
           v = blocks$P_VACANT, 
           shading = vacant_shades)
choro.legend(533000, 161000, 
             sh = vacant_shades)

vacant_shades <- auto.shading(blocks$P_VACANT, 
                              cols = brewer.pal(5, "Greens"))
choropleth(blocks, 
           v = blocks$P_VACANT, 
           shading = vacant_shades)
choro.legend(533000, 161000, 
             sh = vacant_shades)

vacant_shades <- auto.shading(blocks$P_VACANT, 
                              cutter = rangeCuts,
                              n = 5,
                              cols = brewer.pal(5, "Blues"))
choropleth(blocks, 
           v = blocks$P_VACANT, 
           shading = vacant_shades)
choro.legend(533000, 161000, 
             sh = vacant_shades)

vacant_shades
## $breaks
##   #1   #2   #3   #4 
##  7.6 15.0 23.0 30.0 
## 
## $cols
## [1] "#EFF3FF" "#BDD7E7" "#6BAED6" "#3182BD" "#08519C"
## 
## attr(,"class")
## [1] "shading"

Codes

choropleth
## function (sp, v, shading = auto.shading(v), ...) 
## {
##     i = shading$cols[1 + findInterval(v, shading$breaks)]
##     plot(sp, col = i, ...)
## }
## <environment: namespace:GISTools>
auto.shading
## function (x, digits = 2, cutter = quantileCuts, n = 5, params = NA, 
##     cols = brewer.pal(n, "Reds")) 
## {
##     brk = cutter(x, n = n, params = params)
##     if (!is.na(digits)) 
##         brk = signif(brk, digits = digits)
##     brk = sort(brk)
##     brk = brk[!duplicated(brk)]
##     res = list(breaks = brk, cols = cols)
##     class(res) = "shading"
##     res
## }
## <environment: namespace:GISTools>

Mapping Points and Attributes

plot(breach)

plot(blocks)
plot(breach, 
     add = TRUE)

plot(blocks)
plot(breach, 
     add = TRUE, 
     pch = '@')

plot(blocks)
plot(breach, 
     add = TRUE, 
     pch = 16)

plot(blocks)
plot(breach, 
     add = TRUE, 
     pch = 1,
     col = "red")

brewer.pal(5, "Reds")
## [1] "#FEE5D9" "#FCAE91" "#FB6A4A" "#DE2D26" "#A50F15"
pie(rep(1, 5), col = brewer.pal(5, "Reds"))

add.alpha(brewer.pal(5, "Reds"), .50)
## [1] "#FEE5D980" "#FCAE9180" "#FB6A4A80" "#DE2D2680" "#A50F1580"
plot(blocks)
plot(breach, 
     add = TRUE, 
     pch = 1,
     col = "#DE2D2680")

Quakes

data(quakes)
head(quakes)
##      lat   long depth mag stations
## 1 -20.42 181.62   562 4.8       41
## 2 -20.62 181.03   650 4.2       15
## 3 -26.00 184.10    42 5.4       43
## 4 -17.97 181.66   626 4.1       19
## 5 -20.42 181.96   649 4.0       11
## 6 -19.68 184.31   195 4.0       12
class(quakes)
## [1] "data.frame"
coords_quakes <- cbind(long = quakes$long, 
                       lat = quakes$lat)
str(coords_quakes)
##  num [1:1000, 1:2] 182 181 184 182 182 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr [1:2] "long" "lat"
#> SpatialPointDataFrame 만들기
quakes_spdf <- SpatialPointsDataFrame(coords_quakes, data = data.frame(quakes))
par(mfrow = c(1, 2))
plot(quakes_spdf)
plot(quakes_spdf, pch = 1, col = '#FB6A4A80')

par(mfrow = c(1, 1))
library(maps)
## 
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
## 
##     map
## The following object is masked from 'package:GISTools':
## 
##     map.scale
plot(quakes_spdf, pch = 1, col = '#FB6A4A80')
map('world2', fill = FALSE, add = TRUE)

georgia.polys

data(georgia)
class(georgia.polys)
## [1] "list"
summary(georgia.polys)
##        Length Class  Mode   
##   [1,] 250    -none- numeric
##   [2,] 198    -none- numeric
##   [3,] 106    -none- numeric
##   [4,] 248    -none- numeric
##   [5,] 232    -none- numeric
##   [6,] 114    -none- numeric
##   [7,] 176    -none- numeric
##   [8,]  96    -none- numeric
##   [9,] 138    -none- numeric
##  [10,] 320    -none- numeric
##  [11,] 214    -none- numeric
##  [12,]  52    -none- numeric
##  [13,] 326    -none- numeric
##  [14,] 302    -none- numeric
##  [15,] 574    -none- numeric
##  [16,] 380    -none- numeric
##  [17,] 272    -none- numeric
##  [18,] 154    -none- numeric
##  [19,] 186    -none- numeric
##  [20,] 454    -none- numeric
##  [21,]  74    -none- numeric
##  [22,] 112    -none- numeric
##  [23,]  60    -none- numeric
##  [24,] 512    -none- numeric
##  [25,] 360    -none- numeric
##  [26,] 192    -none- numeric
##  [27,]  64    -none- numeric
##  [28,]  94    -none- numeric
##  [29,] 136    -none- numeric
##  [30,] 136    -none- numeric
##  [31,] 146    -none- numeric
##  [32,] 128    -none- numeric
##  [33,] 118    -none- numeric
##  [34,] 184    -none- numeric
##  [35,] 134    -none- numeric
##  [36,] 174    -none- numeric
##  [37,] 230    -none- numeric
##  [38,] 216    -none- numeric
##  [39,] 234    -none- numeric
##  [40,]  86    -none- numeric
##  [41,]  28    -none- numeric
##  [42,] 112    -none- numeric
##  [43,] 100    -none- numeric
##  [44,] 108    -none- numeric
##  [45,] 182    -none- numeric
##  [46,] 134    -none- numeric
##  [47,]  96    -none- numeric
##  [48,]  88    -none- numeric
##  [49,] 178    -none- numeric
##  [50,] 116    -none- numeric
##  [51,] 410    -none- numeric
##  [52,] 250    -none- numeric
##  [53,] 266    -none- numeric
##  [54,] 112    -none- numeric
##  [55,] 146    -none- numeric
##  [56,] 222    -none- numeric
##  [57,] 142    -none- numeric
##  [58,] 144    -none- numeric
##  [59,] 108    -none- numeric
##  [60,] 300    -none- numeric
##  [61,] 194    -none- numeric
##  [62,] 128    -none- numeric
##  [63,] 276    -none- numeric
##  [64,] 150    -none- numeric
##  [65,]  50    -none- numeric
##  [66,] 210    -none- numeric
##  [67,] 148    -none- numeric
##  [68,] 250    -none- numeric
##  [69,] 190    -none- numeric
##  [70,] 250    -none- numeric
##  [71,]  34    -none- numeric
##  [72,] 146    -none- numeric
##  [73,] 114    -none- numeric
##  [74,]  44    -none- numeric
##  [75,] 238    -none- numeric
##  [76,] 310    -none- numeric
##  [77,] 120    -none- numeric
##  [78,] 188    -none- numeric
##  [79,] 144    -none- numeric
##  [80,] 194    -none- numeric
##  [81,] 218    -none- numeric
##  [82,]  52    -none- numeric
##  [83,] 116    -none- numeric
##  [84,]  84    -none- numeric
##  [85,]  34    -none- numeric
##  [86,] 108    -none- numeric
##  [87,] 144    -none- numeric
##  [88,] 152    -none- numeric
##  [89,] 442    -none- numeric
##  [90,] 198    -none- numeric
##  [91,] 300    -none- numeric
##  [92,] 352    -none- numeric
##  [93,] 212    -none- numeric
##  [94,] 234    -none- numeric
##  [95,] 286    -none- numeric
##  [96,] 150    -none- numeric
##  [97,] 252    -none- numeric
##  [98,] 148    -none- numeric
##  [99,] 164    -none- numeric
## [100,]  48    -none- numeric
## [101,] 192    -none- numeric
## [102,] 102    -none- numeric
## [103,] 186    -none- numeric
## [104,] 170    -none- numeric
## [105,] 276    -none- numeric
## [106,] 210    -none- numeric
## [107,] 200    -none- numeric
## [108,] 222    -none- numeric
## [109,] 256    -none- numeric
## [110,]  50    -none- numeric
## [111,] 124    -none- numeric
## [112,]  80    -none- numeric
## [113,] 374    -none- numeric
## [114,] 128    -none- numeric
## [115,]  48    -none- numeric
## [116,]  96    -none- numeric
## [117,] 184    -none- numeric
## [118,] 108    -none- numeric
## [119,] 326    -none- numeric
## [120,] 128    -none- numeric
## [121,] 230    -none- numeric
## [122,] 114    -none- numeric
## [123,]  70    -none- numeric
## [124,] 436    -none- numeric
## [125,] 164    -none- numeric
## [126,] 172    -none- numeric
## [127,]  94    -none- numeric
## [128,] 166    -none- numeric
## [129,] 172    -none- numeric
## [130,] 214    -none- numeric
## [131,] 198    -none- numeric
## [132,] 228    -none- numeric
## [133,] 264    -none- numeric
## [134,] 416    -none- numeric
## [135,] 146    -none- numeric
## [136,]  68    -none- numeric
## [137,]  94    -none- numeric
## [138,] 182    -none- numeric
## [139,] 130    -none- numeric
## [140,] 182    -none- numeric
## [141,]  64    -none- numeric
## [142,] 114    -none- numeric
## [143,] 272    -none- numeric
## [144,] 256    -none- numeric
## [145,] 174    -none- numeric
## [146,]  54    -none- numeric
## [147,] 134    -none- numeric
## [148,] 188    -none- numeric
## [149,] 246    -none- numeric
## [150,] 378    -none- numeric
## [151,] 342    -none- numeric
## [152,]  96    -none- numeric
## [153,] 330    -none- numeric
## [154,] 226    -none- numeric
## [155,] 242    -none- numeric
## [156,] 232    -none- numeric
## [157,] 274    -none- numeric
## [158,] 242    -none- numeric
## [159,] 204    -none- numeric
str(georgia.polys)
## List of 159
##  $ : num [1:125, 1:2] 1292287 1292654 1292949 1294045 1294603 ...
##  $ : num [1:99, 1:2] 1263206 1264530 1263799 1263714 1263095 ...
##  $ : num [1:53, 1:2] 1267843 1270202 1271306 1272213 1272824 ...
##  $ : num [1:124, 1:2] 1120149 1120164 1119692 1119295 1118798 ...
##  $ : num [1:116, 1:2] 1175513 1177004 1192290 1192624 1192486 ...
##  $ : num [1:57, 1:2] 1145286 1147147 1147695 1147509 1147702 ...
##  $ : num [1:88, 1:2] 1139961 1139952 1130886 1129920 1129514 ...
##  $ : num [1:48, 1:2] 1032460 1033151 1034035 1034110 1033265 ...
##  $ : num [1:69, 1:2] 1204456 1205348 1206102 1206600 1207069 ...
##  $ : num [1:160, 1:2] 1213059 1213172 1212754 1212907 1213424 ...
##  $ : num [1:107, 1:2] 1123543 1130095 1133489 1137617 1137047 ...
##  $ : num [1:26, 1:2] 1188893 1199421 1195803 1185260 1187452 ...
##  $ : num [1:163, 1:2] 1347952 1348302 1348082 1347279 1346895 ...
##  $ : num [1:151, 1:2] 1163881 1179257 1178518 1179108 1179011 ...
##  $ : num [1:287, 1:2] 1360177 1360720 1361011 1360864 1361293 ...
##  $ : num [1:190, 1:2] 1315860 1316107 1316888 1317934 1318723 ...
##  $ : num [1:136, 1:2] 1304940 1305548 1307061 1307467 1309244 ...
##  $ : num [1:77, 1:2] 1118825 1119066 1119566 1119167 1121554 ...
##  $ : num [1:93, 1:2] 1088588 1089134 1088424 1089111 1089154 ...
##  $ : num [1:227, 1:2] 1333407 1333712 1333271 1333628 1333119 ...
##  $ : num [1:37, 1:2] 1300215 1306107 1305910 1305934 1305511 ...
##  $ : num [1:56, 1:2] 1018187 1018834 1017997 1018011 1018097 ...
##  $ : num [1:30, 1:2] 995434 995645 994050 994430 993887 ...
##  $ : num [1:256, 1:2] 1315560 1320365 1321194 1333407 1334119 ...
##  $ : num [1:180, 1:2] 1366749 1382496 1387451 1386801 1388059 ...
##  $ : num [1:96, 1:2] 1058913 1059361 1057588 1060919 1047574 ...
##  $ : num [1:32, 1:2] 989052 987992 986368 985657 985105 ...
##  $ : num [1:47, 1:2] 1068729 1069256 1071279 1064966 1064189 ...
##  $ : num [1:68, 1:2] 1164824 1164115 1164104 1163595 1164489 ...
##  $ : num [1:68, 1:2] 1038886 1039654 1040586 1040981 1041848 ...
##  $ : num [1:73, 1:2] 1076638 1076740 1077620 1077721 1078582 ...
##  $ : num [1:64, 1:2] 1262010 1272080 1272522 1273357 1274083 ...
##  $ : num [1:59, 1:2] 1029201 1036370 1039497 1039561 1040472 ...
##  $ : num [1:92, 1:2] 1236803 1238991 1258555 1260244 1263257 ...
##  $ : num [1:67, 1:2] 1180769 1180913 1181429 1181524 1182013 ...
##  $ : num [1:87, 1:2] 1264293 1265492 1266277 1266521 1267204 ...
##  $ : num [1:115, 1:2] 1187811 1188233 1187860 1188054 1187871 ...
##  $ : num [1:108, 1:2] 1048587 1048052 1047461 1047758 1047537 ...
##  $ : num [1:117, 1:2] 1123543 1123870 1125238 1125548 1126286 ...
##  $ : num [1:43, 1:2] 1161518 1163783 1164470 1146712 1145790 ...
##  $ : num [1:14, 1:2] 960827 960251 956009 955029 955940 ...
##  $ : num [1:56, 1:2] 1071887 1071728 1072304 1080546 1081978 ...
##  $ : num [1:50, 1:2] 1102905 1104749 1107760 1098833 1061672 ...
##  $ : num [1:54, 1:2] 1098712 1096077 1092233 1092201 1090964 ...
##  $ : num [1:91, 1:2] 1199421 1217335 1226228 1226459 1227872 ...
##  $ : num [1:67, 1:2] 1157182 1158036 1158127 1158577 1157712 ...
##  $ : num [1:48, 1:2] 1102889 1126736 1126850 1127320 1127690 ...
##  $ : num [1:44, 1:2] 1033955 1043582 1043410 1048227 1047625 ...
##  $ : num [1:89, 1:2] 1055504 1055634 1056842 1056694 1057683 ...
##  $ : num [1:58, 1:2] 1234343 1234760 1234918 1235370 1236656 ...
##  $ : num [1:205, 1:2] 1369072 1369386 1369271 1369873 1369909 ...
##  $ : num [1:125, 1:2] 1177797 1183012 1184785 1185896 1185284 ...
##  $ : num [1:133, 1:2] 1285172 1293325 1301756 1300262 1300215 ...
##  $ : num [1:56, 1:2] 1310313 1310484 1310843 1311737 1314887 ...
##  $ : num [1:73, 1:2] 1054566 1071855 1070760 1070285 1070016 ...
##  $ : num [1:111, 1:2] 1061744 1063484 1064200 1064394 1065808 ...
##  $ : num [1:71, 1:2] 992544 992688 993153 993629 991241 ...
##  $ : num [1:72, 1:2] 1069256 1096565 1097688 1097739 1097307 ...
##  $ : num [1:54, 1:2] 1170770 1170964 1171820 1172635 1173287 ...
##  $ : num [1:150, 1:2] 1058286 1057847 1058185 1058508 1059555 ...
##  $ : num [1:97, 1:2] 1070923 1070663 1069911 1069496 1069192 ...
##  $ : num [1:64, 1:2] 1251398 1239001 1239358 1239991 1240309 ...
##  $ : num [1:138, 1:2] 1347952 1348601 1349930 1350460 1350463 ...
##  $ : num [1:75, 1:2] 1005967 1006474 1006715 1010723 1010827 ...
##  $ : num [1:25, 1:2] 1102905 1127427 1128414 1128890 1128762 ...
##  $ : num [1:105, 1:2] 1155854 1165814 1165155 1165192 1165589 ...
##  $ : num [1:74, 1:2] 1112155 1109239 1110645 1112386 1113099 ...
##  $ : num [1:125, 1:2] 1117103 1117373 1118258 1119095 1119598 ...
##  $ : num [1:95, 1:2] 1104431 1109396 1109259 1110258 1110377 ...
##  $ : num [1:125, 1:2] 1210300 1211423 1211627 1212028 1212128 ...
##  $ : num [1:17, 1:2] 1003022 1004268 1005342 1004296 1005409 ...
##  $ : num [1:73, 1:2] 1033689 1034990 1035053 1035665 1043933 ...
##  $ : num [1:57, 1:2] 1176087 1177791 1178268 1180708 1181536 ...
##  $ : num [1:22, 1:2] 986797 1012381 1019505 1019442 1020341 ...
##  $ : num [1:119, 1:2] 1076638 1080088 1080307 1081995 1081781 ...
##  $ : num [1:155, 1:2] 1143436 1143422 1146977 1148476 1150074 ...
##  $ : num [1:60, 1:2] 1180061 1187796 1187656 1190495 1190664 ...
##  $ : num [1:94, 1:2] 1127656 1128002 1129884 1130496 1133580 ...
##  $ : num [1:72, 1:2] 1148060 1148275 1148661 1148728 1150824 ...
##  $ : num [1:97, 1:2] 1272207 1274255 1265956 1267370 1264520 ...
##  $ : num [1:109, 1:2] 1257970 1259081 1260114 1260995 1262022 ...
##  $ : num [1:26, 1:2] 1318306 1312852 1313326 1314522 1314739 ...
##  $ : num [1:58, 1:2] 1250375 1251704 1252449 1253825 1255489 ...
##  $ : num [1:42, 1:2] 1150824 1160389 1160971 1161313 1163673 ...
##  $ : num [1:17, 1:2] 1097238 1104802 1108129 1107254 1107431 ...
##  $ : num [1:54, 1:2] 1226717 1233822 1238599 1237436 1236656 ...
##  $ : num [1:72, 1:2] 1188893 1204709 1211929 1220520 1228059 ...
##  $ : num [1:76, 1:2] 1133983 1133276 1133320 1133781 1133331 ...
##  $ : num [1:221, 1:2] 1333189 1336515 1336762 1336895 1337737 ...
##  $ : num [1:99, 1:2] 1220666 1221242 1221480 1222027 1222117 ...
##  $ : num [1:150, 1:2] 1318149 1317916 1317679 1317023 1316846 ...
##  $ : num [1:176, 1:2] 1188569 1205677 1214880 1216488 1217729 ...
##  $ : num [1:106, 1:2] 1074049 1074331 1074532 1074932 1075141 ...
##  $ : num [1:117, 1:2] 1241266 1241423 1242286 1242690 1243154 ...
##  $ : num [1:143, 1:2] 1394263 1393253 1392470 1388469 1388156 ...
##  $ : num [1:75, 1:2] 1113237 1113319 1115117 1115361 1116923 ...
##  $ : num [1:126, 1:2] 1173889 1173840 1177797 1177804 1177419 ...
##  $ : num [1:74, 1:2] 1076440 1076774 1075883 1075999 1076920 ...
##  $ : num [1:82, 1:2] 1029476 1030403 1029973 1042605 1042508 ...
##   [list output truncated]
tmp <- georgia.polys[c(1, 3, 151, 113)]
t1 <- Polygon(tmp[1]); t1 <- Polygons(list(t1), "1")
t2 <- Polygon(tmp[2]); t2 <- Polygons(list(t2), "2")
t3 <- Polygon(tmp[3]); t3 <- Polygons(list(t3), "3")
t4 <- Polygon(tmp[4]); t4 <- Polygons(list(t4), "4")
tmp_Sp <- SpatialPolygons(list(t1, t2, t3, t4), 1:4)
plot(tmp_Sp)

names <- c("Appling", "Bacon", "Wayne", "Pierce")
tmp_spdf <- SpatialPolygonsDataFrame(tmp_Sp, data = data.frame(names))
data.frame(tmp_spdf)
##     names
## 1 Appling
## 2   Bacon
## 3   Wayne
## 4  Pierce
tmp_spdf@data
##     names
## 1 Appling
## 2   Bacon
## 3   Wayne
## 4  Pierce
plot(tmp_spdf, col = 2:5)

quakes

par(mfrow = c(2, 2))
choropleth(quakes_spdf, 
           v = quakes$mag)
shades <- auto.shading(quakes$mag, 
                       n = 6,
                       cols = brewer.pal(6, "Greens"))
str(shades)
## List of 2
##  $ breaks: Named num [1:5] 4.2 4.4 4.6 4.7 5
##   ..- attr(*, "names")= chr [1:5] "16.66667%" "33.33333%" "50%" "66.66667%" ...
##  $ cols  : chr [1:6] "#EDF8E9" "#C7E9C0" "#A1D99B" "#74C476" ...
##  - attr(*, "class")= chr "shading"
choropleth(quakes_spdf, 
           v = quakes$mag,
           shading = shades,
           pch = 1)
shades$cols <- add.alpha(shades$cols, 0.5)
choropleth(quakes_spdf, 
           v = quakes$mag,
           shading = shades,
           pch = 20)
mag_z <- (quakes$mag - min(quakes$mag)) / max(quakes$mag)
plot(quakes_spdf, 
     cex = mag_z * 3,
     pch = 1,
     col = '#FB6A4A80')

par(mfrow = c(1, 1))
par(mfrow = c(1, 2))
tmp2 <- cut(quakes$mag, 
            fivenum(quakes$mag),
            include.lowest = TRUE)
str(tmp2)
##  Factor w/ 4 levels "[4,4.3]","(4.3,4.6]",..: 3 1 4 1 1 1 3 2 3 1 ...
class_mag <- match(tmp2, levels(tmp2))
str(class_mag)
##  int [1:1000] 3 1 4 1 1 1 3 2 3 1 ...
pch_var <- c(0, 1, 2, 5)
plot(quakes_spdf,
     pch = pch_var[class_mag],
     cex = 0.7,
     col = '#252525B3')
index_1 <- (quakes$mag >= 4 & quakes$mag < 5) + 0
index_2 <- (quakes$mag >= 5 & quakes$mag < 5.5) * 2
index_3 <- (quakes$mag >= 5.5) * 3
cbind(index_1, index_2, index_3)
##         index_1 index_2 index_3
##    [1,]       1       0       0
##    [2,]       1       0       0
##    [3,]       0       2       0
##    [4,]       1       0       0
##    [5,]       1       0       0
##    [6,]       1       0       0
##    [7,]       1       0       0
##    [8,]       1       0       0
##    [9,]       1       0       0
##   [10,]       1       0       0
##   [11,]       1       0       0
##   [12,]       1       0       0
##   [13,]       1       0       0
##   [14,]       1       0       0
##   [15,]       0       0       3
##   [16,]       1       0       0
##   [17,]       0       0       3
##   [18,]       1       0       0
##   [19,]       1       0       0
##   [20,]       1       0       0
##   [21,]       1       0       0
##   [22,]       1       0       0
##   [23,]       1       0       0
##   [24,]       1       0       0
##   [25,]       0       2       0
##   [26,]       1       0       0
##   [27,]       1       0       0
##   [28,]       0       2       0
##   [29,]       1       0       0
##   [30,]       1       0       0
##   [31,]       1       0       0
##   [32,]       1       0       0
##   [33,]       1       0       0
##   [34,]       1       0       0
##   [35,]       1       0       0
##   [36,]       1       0       0
##   [37,]       1       0       0
##   [38,]       1       0       0
##   [39,]       1       0       0
##   [40,]       1       0       0
##   [41,]       1       0       0
##   [42,]       1       0       0
##   [43,]       1       0       0
##   [44,]       1       0       0
##   [45,]       1       0       0
##   [46,]       1       0       0
##   [47,]       1       0       0
##   [48,]       1       0       0
##   [49,]       1       0       0
##   [50,]       0       2       0
##   [51,]       1       0       0
##   [52,]       1       0       0
##   [53,]       1       0       0
##   [54,]       1       0       0
##   [55,]       1       0       0
##   [56,]       1       0       0
##   [57,]       1       0       0
##   [58,]       1       0       0
##   [59,]       1       0       0
##   [60,]       1       0       0
##   [61,]       1       0       0
##   [62,]       1       0       0
##   [63,]       0       2       0
##   [64,]       1       0       0
##   [65,]       1       0       0
##   [66,]       1       0       0
##   [67,]       1       0       0
##   [68,]       0       2       0
##   [69,]       1       0       0
##   [70,]       0       0       3
##   [71,]       1       0       0
##   [72,]       1       0       0
##   [73,]       1       0       0
##   [74,]       0       2       0
##   [75,]       1       0       0
##   [76,]       1       0       0
##   [77,]       1       0       0
##   [78,]       1       0       0
##   [79,]       1       0       0
##   [80,]       0       2       0
##   [81,]       0       2       0
##   [82,]       1       0       0
##   [83,]       1       0       0
##   [84,]       1       0       0
##   [85,]       1       0       0
##   [86,]       1       0       0
##   [87,]       1       0       0
##   [88,]       1       0       0
##   [89,]       1       0       0
##   [90,]       1       0       0
##   [91,]       0       2       0
##   [92,]       1       0       0
##   [93,]       0       2       0
##   [94,]       1       0       0
##   [95,]       1       0       0
##   [96,]       1       0       0
##   [97,]       1       0       0
##   [98,]       0       2       0
##   [99,]       0       2       0
##  [100,]       1       0       0
##  [101,]       1       0       0
##  [102,]       1       0       0
##  [103,]       1       0       0
##  [104,]       1       0       0
##  [105,]       1       0       0
##  [106,]       1       0       0
##  [107,]       1       0       0
##  [108,]       1       0       0
##  [109,]       0       0       3
##  [110,]       0       2       0
##  [111,]       1       0       0
##  [112,]       1       0       0
##  [113,]       1       0       0
##  [114,]       1       0       0
##  [115,]       1       0       0
##  [116,]       1       0       0
##  [117,]       0       2       0
##  [118,]       1       0       0
##  [119,]       1       0       0
##  [120,]       1       0       0
##  [121,]       1       0       0
##  [122,]       1       0       0
##  [123,]       1       0       0
##  [124,]       1       0       0
##  [125,]       1       0       0
##  [126,]       0       2       0
##  [127,]       1       0       0
##  [128,]       0       2       0
##  [129,]       1       0       0
##  [130,]       1       0       0
##  [131,]       1       0       0
##  [132,]       1       0       0
##  [133,]       1       0       0
##  [134,]       1       0       0
##  [135,]       1       0       0
##  [136,]       1       0       0
##  [137,]       0       2       0
##  [138,]       1       0       0
##  [139,]       1       0       0
##  [140,]       1       0       0
##  [141,]       1       0       0
##  [142,]       1       0       0
##  [143,]       0       2       0
##  [144,]       1       0       0
##  [145,]       1       0       0
##  [146,]       1       0       0
##  [147,]       1       0       0
##  [148,]       1       0       0
##  [149,]       0       2       0
##  [150,]       1       0       0
##  [151,]       0       0       3
##  [152,]       0       0       3
##  [153,]       1       0       0
##  [154,]       1       0       0
##  [155,]       1       0       0
##  [156,]       1       0       0
##  [157,]       1       0       0
##  [158,]       1       0       0
##  [159,]       1       0       0
##  [160,]       1       0       0
##  [161,]       1       0       0
##  [162,]       1       0       0
##  [163,]       1       0       0
##  [164,]       1       0       0
##  [165,]       1       0       0
##  [166,]       0       2       0
##  [167,]       0       0       3
##  [168,]       0       2       0
##  [169,]       1       0       0
##  [170,]       1       0       0
##  [171,]       1       0       0
##  [172,]       1       0       0
##  [173,]       1       0       0
##  [174,]       1       0       0
##  [175,]       1       0       0
##  [176,]       0       0       3
##  [177,]       0       2       0
##  [178,]       1       0       0
##  [179,]       1       0       0
##  [180,]       1       0       0
##  [181,]       1       0       0
##  [182,]       1       0       0
##  [183,]       1       0       0
##  [184,]       1       0       0
##  [185,]       1       0       0
##  [186,]       1       0       0
##  [187,]       1       0       0
##  [188,]       1       0       0
##  [189,]       1       0       0
##  [190,]       1       0       0
##  [191,]       0       2       0
##  [192,]       1       0       0
##  [193,]       1       0       0
##  [194,]       1       0       0
##  [195,]       1       0       0
##  [196,]       1       0       0
##  [197,]       1       0       0
##  [198,]       1       0       0
##  [199,]       1       0       0
##  [200,]       0       2       0
##  [201,]       1       0       0
##  [202,]       1       0       0
##  [203,]       1       0       0
##  [204,]       1       0       0
##  [205,]       1       0       0
##  [206,]       1       0       0
##  [207,]       0       2       0
##  [208,]       1       0       0
##  [209,]       1       0       0
##  [210,]       1       0       0
##  [211,]       1       0       0
##  [212,]       1       0       0
##  [213,]       1       0       0
##  [214,]       0       2       0
##  [215,]       1       0       0
##  [216,]       1       0       0
##  [217,]       1       0       0
##  [218,]       1       0       0
##  [219,]       1       0       0
##  [220,]       1       0       0
##  [221,]       1       0       0
##  [222,]       1       0       0
##  [223,]       1       0       0
##  [224,]       1       0       0
##  [225,]       1       0       0
##  [226,]       1       0       0
##  [227,]       1       0       0
##  [228,]       1       0       0
##  [229,]       0       2       0
##  [230,]       0       2       0
##  [231,]       1       0       0
##  [232,]       1       0       0
##  [233,]       1       0       0
##  [234,]       1       0       0
##  [235,]       1       0       0
##  [236,]       1       0       0
##  [237,]       1       0       0
##  [238,]       0       2       0
##  [239,]       1       0       0
##  [240,]       1       0       0
##  [241,]       1       0       0
##  [242,]       1       0       0
##  [243,]       0       2       0
##  [244,]       1       0       0
##  [245,]       0       2       0
##  [246,]       1       0       0
##  [247,]       1       0       0
##  [248,]       1       0       0
##  [249,]       0       2       0
##  [250,]       1       0       0
##  [251,]       1       0       0
##  [252,]       1       0       0
##  [253,]       0       2       0
##  [254,]       1       0       0
##  [255,]       1       0       0
##  [256,]       1       0       0
##  [257,]       1       0       0
##  [258,]       1       0       0
##  [259,]       1       0       0
##  [260,]       1       0       0
##  [261,]       0       2       0
##  [262,]       1       0       0
##  [263,]       1       0       0
##  [264,]       1       0       0
##  [265,]       1       0       0
##  [266,]       1       0       0
##  [267,]       1       0       0
##  [268,]       1       0       0
##  [269,]       1       0       0
##  [270,]       1       0       0
##  [271,]       1       0       0
##  [272,]       1       0       0
##  [273,]       1       0       0
##  [274,]       1       0       0
##  [275,]       0       0       3
##  [276,]       1       0       0
##  [277,]       0       2       0
##  [278,]       1       0       0
##  [279,]       1       0       0
##  [280,]       0       2       0
##  [281,]       1       0       0
##  [282,]       1       0       0
##  [283,]       1       0       0
##  [284,]       1       0       0
##  [285,]       1       0       0
##  [286,]       1       0       0
##  [287,]       1       0       0
##  [288,]       1       0       0
##  [289,]       1       0       0
##  [290,]       0       2       0
##  [291,]       0       2       0
##  [292,]       1       0       0
##  [293,]       1       0       0
##  [294,]       1       0       0
##  [295,]       0       2       0
##  [296,]       0       2       0
##  [297,]       0       0       3
##  [298,]       1       0       0
##  [299,]       1       0       0
##  [300,]       1       0       0
##  [301,]       1       0       0
##  [302,]       1       0       0
##  [303,]       1       0       0
##  [304,]       1       0       0
##  [305,]       1       0       0
##  [306,]       1       0       0
##  [307,]       1       0       0
##  [308,]       1       0       0
##  [309,]       1       0       0
##  [310,]       1       0       0
##  [311,]       1       0       0
##  [312,]       0       2       0
##  [313,]       0       2       0
##  [314,]       1       0       0
##  [315,]       1       0       0
##  [316,]       1       0       0
##  [317,]       1       0       0
##  [318,]       0       2       0
##  [319,]       1       0       0
##  [320,]       1       0       0
##  [321,]       1       0       0
##  [322,]       0       2       0
##  [323,]       1       0       0
##  [324,]       1       0       0
##  [325,]       1       0       0
##  [326,]       1       0       0
##  [327,]       1       0       0
##  [328,]       1       0       0
##  [329,]       1       0       0
##  [330,]       0       2       0
##  [331,]       0       2       0
##  [332,]       1       0       0
##  [333,]       1       0       0
##  [334,]       0       2       0
##  [335,]       0       2       0
##  [336,]       1       0       0
##  [337,]       1       0       0
##  [338,]       0       2       0
##  [339,]       1       0       0
##  [340,]       1       0       0
##  [341,]       1       0       0
##  [342,]       1       0       0
##  [343,]       1       0       0
##  [344,]       1       0       0
##  [345,]       1       0       0
##  [346,]       1       0       0
##  [347,]       1       0       0
##  [348,]       1       0       0
##  [349,]       0       2       0
##  [350,]       1       0       0
##  [351,]       1       0       0
##  [352,]       1       0       0
##  [353,]       1       0       0
##  [354,]       0       0       3
##  [355,]       1       0       0
##  [356,]       0       2       0
##  [357,]       0       2       0
##  [358,]       0       0       3
##  [359,]       1       0       0
##  [360,]       1       0       0
##  [361,]       1       0       0
##  [362,]       1       0       0
##  [363,]       0       2       0
##  [364,]       1       0       0
##  [365,]       1       0       0
##  [366,]       1       0       0
##  [367,]       0       2       0
##  [368,]       1       0       0
##  [369,]       1       0       0
##  [370,]       1       0       0
##  [371,]       0       2       0
##  [372,]       0       2       0
##  [373,]       0       2       0
##  [374,]       0       2       0
##  [375,]       1       0       0
##  [376,]       0       0       3
##  [377,]       1       0       0
##  [378,]       0       2       0
##  [379,]       1       0       0
##  [380,]       0       0       3
##  [381,]       0       2       0
##  [382,]       1       0       0
##  [383,]       0       2       0
##  [384,]       0       2       0
##  [385,]       0       2       0
##  [386,]       0       2       0
##  [387,]       1       0       0
##  [388,]       1       0       0
##  [389,]       1       0       0
##  [390,]       1       0       0
##  [391,]       1       0       0
##  [392,]       1       0       0
##  [393,]       1       0       0
##  [394,]       1       0       0
##  [395,]       1       0       0
##  [396,]       1       0       0
##  [397,]       0       2       0
##  [398,]       0       2       0
##  [399,]       0       0       3
##  [400,]       0       2       0
##  [401,]       1       0       0
##  [402,]       1       0       0
##  [403,]       1       0       0
##  [404,]       0       2       0
##  [405,]       1       0       0
##  [406,]       1       0       0
##  [407,]       1       0       0
##  [408,]       1       0       0
##  [409,]       1       0       0
##  [410,]       1       0       0
##  [411,]       1       0       0
##  [412,]       1       0       0
##  [413,]       1       0       0
##  [414,]       1       0       0
##  [415,]       1       0       0
##  [416,]       0       2       0
##  [417,]       1       0       0
##  [418,]       1       0       0
##  [419,]       1       0       0
##  [420,]       1       0       0
##  [421,]       1       0       0
##  [422,]       1       0       0
##  [423,]       1       0       0
##  [424,]       0       2       0
##  [425,]       1       0       0
##  [426,]       1       0       0
##  [427,]       1       0       0
##  [428,]       1       0       0
##  [429,]       1       0       0
##  [430,]       1       0       0
##  [431,]       1       0       0
##  [432,]       1       0       0
##  [433,]       1       0       0
##  [434,]       1       0       0
##  [435,]       1       0       0
##  [436,]       1       0       0
##  [437,]       1       0       0
##  [438,]       1       0       0
##  [439,]       1       0       0
##  [440,]       1       0       0
##  [441,]       1       0       0
##  [442,]       1       0       0
##  [443,]       1       0       0
##  [444,]       1       0       0
##  [445,]       0       2       0
##  [446,]       1       0       0
##  [447,]       1       0       0
##  [448,]       0       2       0
##  [449,]       0       0       3
##  [450,]       1       0       0
##  [451,]       1       0       0
##  [452,]       1       0       0
##  [453,]       1       0       0
##  [454,]       1       0       0
##  [455,]       1       0       0
##  [456,]       1       0       0
##  [457,]       1       0       0
##  [458,]       1       0       0
##  [459,]       0       2       0
##  [460,]       1       0       0
##  [461,]       1       0       0
##  [462,]       0       2       0
##  [463,]       0       2       0
##  [464,]       1       0       0
##  [465,]       0       2       0
##  [466,]       1       0       0
##  [467,]       1       0       0
##  [468,]       1       0       0
##  [469,]       1       0       0
##  [470,]       1       0       0
##  [471,]       1       0       0
##  [472,]       1       0       0
##  [473,]       1       0       0
##  [474,]       0       2       0
##  [475,]       1       0       0
##  [476,]       1       0       0
##  [477,]       0       2       0
##  [478,]       1       0       0
##  [479,]       1       0       0
##  [480,]       1       0       0
##  [481,]       1       0       0
##  [482,]       1       0       0
##  [483,]       1       0       0
##  [484,]       1       0       0
##  [485,]       1       0       0
##  [486,]       0       2       0
##  [487,]       1       0       0
##  [488,]       1       0       0
##  [489,]       1       0       0
##  [490,]       1       0       0
##  [491,]       1       0       0
##  [492,]       1       0       0
##  [493,]       1       0       0
##  [494,]       1       0       0
##  [495,]       1       0       0
##  [496,]       0       0       3
##  [497,]       1       0       0
##  [498,]       1       0       0
##  [499,]       1       0       0
##  [500,]       1       0       0
##  [501,]       1       0       0
##  [502,]       1       0       0
##  [503,]       1       0       0
##  [504,]       1       0       0
##  [505,]       1       0       0
##  [506,]       1       0       0
##  [507,]       1       0       0
##  [508,]       1       0       0
##  [509,]       1       0       0
##  [510,]       1       0       0
##  [511,]       1       0       0
##  [512,]       0       0       3
##  [513,]       1       0       0
##  [514,]       1       0       0
##  [515,]       1       0       0
##  [516,]       1       0       0
##  [517,]       1       0       0
##  [518,]       1       0       0
##  [519,]       1       0       0
##  [520,]       1       0       0
##  [521,]       1       0       0
##  [522,]       1       0       0
##  [523,]       1       0       0
##  [524,]       1       0       0
##  [525,]       0       0       3
##  [526,]       1       0       0
##  [527,]       1       0       0
##  [528,]       0       2       0
##  [529,]       1       0       0
##  [530,]       1       0       0
##  [531,]       0       0       3
##  [532,]       1       0       0
##  [533,]       1       0       0
##  [534,]       1       0       0
##  [535,]       1       0       0
##  [536,]       1       0       0
##  [537,]       1       0       0
##  [538,]       1       0       0
##  [539,]       0       2       0
##  [540,]       1       0       0
##  [541,]       0       0       3
##  [542,]       1       0       0
##  [543,]       1       0       0
##  [544,]       1       0       0
##  [545,]       1       0       0
##  [546,]       1       0       0
##  [547,]       0       2       0
##  [548,]       1       0       0
##  [549,]       0       2       0
##  [550,]       1       0       0
##  [551,]       1       0       0
##  [552,]       1       0       0
##  [553,]       1       0       0
##  [554,]       1       0       0
##  [555,]       1       0       0
##  [556,]       1       0       0
##  [557,]       1       0       0
##  [558,]       0       0       3
##  [559,]       1       0       0
##  [560,]       1       0       0
##  [561,]       1       0       0
##  [562,]       1       0       0
##  [563,]       1       0       0
##  [564,]       0       2       0
##  [565,]       1       0       0
##  [566,]       1       0       0
##  [567,]       1       0       0
##  [568,]       0       2       0
##  [569,]       1       0       0
##  [570,]       0       0       3
##  [571,]       0       2       0
##  [572,]       1       0       0
##  [573,]       1       0       0
##  [574,]       0       2       0
##  [575,]       1       0       0
##  [576,]       1       0       0
##  [577,]       1       0       0
##  [578,]       1       0       0
##  [579,]       0       2       0
##  [580,]       0       2       0
##  [581,]       1       0       0
##  [582,]       1       0       0
##  [583,]       0       2       0
##  [584,]       1       0       0
##  [585,]       1       0       0
##  [586,]       1       0       0
##  [587,]       1       0       0
##  [588,]       1       0       0
##  [589,]       1       0       0
##  [590,]       0       2       0
##  [591,]       1       0       0
##  [592,]       1       0       0
##  [593,]       1       0       0
##  [594,]       1       0       0
##  [595,]       1       0       0
##  [596,]       1       0       0
##  [597,]       1       0       0
##  [598,]       1       0       0
##  [599,]       1       0       0
##  [600,]       1       0       0
##  [601,]       0       2       0
##  [602,]       1       0       0
##  [603,]       1       0       0
##  [604,]       1       0       0
##  [605,]       0       0       3
##  [606,]       1       0       0
##  [607,]       1       0       0
##  [608,]       1       0       0
##  [609,]       1       0       0
##  [610,]       1       0       0
##  [611,]       1       0       0
##  [612,]       1       0       0
##  [613,]       1       0       0
##  [614,]       1       0       0
##  [615,]       0       2       0
##  [616,]       1       0       0
##  [617,]       1       0       0
##  [618,]       0       2       0
##  [619,]       1       0       0
##  [620,]       1       0       0
##  [621,]       1       0       0
##  [622,]       1       0       0
##  [623,]       0       2       0
##  [624,]       0       2       0
##  [625,]       1       0       0
##  [626,]       1       0       0
##  [627,]       1       0       0
##  [628,]       1       0       0
##  [629,]       0       2       0
##  [630,]       1       0       0
##  [631,]       1       0       0
##  [632,]       1       0       0
##  [633,]       1       0       0
##  [634,]       1       0       0
##  [635,]       1       0       0
##  [636,]       0       0       3
##  [637,]       1       0       0
##  [638,]       0       2       0
##  [639,]       1       0       0
##  [640,]       1       0       0
##  [641,]       1       0       0
##  [642,]       1       0       0
##  [643,]       0       2       0
##  [644,]       1       0       0
##  [645,]       1       0       0
##  [646,]       1       0       0
##  [647,]       1       0       0
##  [648,]       1       0       0
##  [649,]       0       0       3
##  [650,]       1       0       0
##  [651,]       0       2       0
##  [652,]       1       0       0
##  [653,]       0       0       3
##  [654,]       1       0       0
##  [655,]       1       0       0
##  [656,]       1       0       0
##  [657,]       0       2       0
##  [658,]       1       0       0
##  [659,]       1       0       0
##  [660,]       1       0       0
##  [661,]       1       0       0
##  [662,]       1       0       0
##  [663,]       0       0       3
##  [664,]       0       2       0
##  [665,]       1       0       0
##  [666,]       0       2       0
##  [667,]       1       0       0
##  [668,]       1       0       0
##  [669,]       1       0       0
##  [670,]       1       0       0
##  [671,]       1       0       0
##  [672,]       1       0       0
##  [673,]       1       0       0
##  [674,]       1       0       0
##  [675,]       0       2       0
##  [676,]       1       0       0
##  [677,]       1       0       0
##  [678,]       1       0       0
##  [679,]       1       0       0
##  [680,]       1       0       0
##  [681,]       0       2       0
##  [682,]       1       0       0
##  [683,]       1       0       0
##  [684,]       1       0       0
##  [685,]       1       0       0
##  [686,]       1       0       0
##  [687,]       1       0       0
##  [688,]       1       0       0
##  [689,]       0       2       0
##  [690,]       1       0       0
##  [691,]       1       0       0
##  [692,]       0       2       0
##  [693,]       1       0       0
##  [694,]       1       0       0
##  [695,]       1       0       0
##  [696,]       1       0       0
##  [697,]       0       2       0
##  [698,]       1       0       0
##  [699,]       1       0       0
##  [700,]       0       2       0
##  [701,]       1       0       0
##  [702,]       0       2       0
##  [703,]       0       2       0
##  [704,]       1       0       0
##  [705,]       1       0       0
##  [706,]       1       0       0
##  [707,]       1       0       0
##  [708,]       0       2       0
##  [709,]       1       0       0
##  [710,]       1       0       0
##  [711,]       1       0       0
##  [712,]       0       0       3
##  [713,]       1       0       0
##  [714,]       0       2       0
##  [715,]       1       0       0
##  [716,]       1       0       0
##  [717,]       1       0       0
##  [718,]       1       0       0
##  [719,]       1       0       0
##  [720,]       1       0       0
##  [721,]       1       0       0
##  [722,]       1       0       0
##  [723,]       1       0       0
##  [724,]       0       2       0
##  [725,]       1       0       0
##  [726,]       1       0       0
##  [727,]       1       0       0
##  [728,]       1       0       0
##  [729,]       1       0       0
##  [730,]       1       0       0
##  [731,]       1       0       0
##  [732,]       1       0       0
##  [733,]       1       0       0
##  [734,]       1       0       0
##  [735,]       1       0       0
##  [736,]       1       0       0
##  [737,]       1       0       0
##  [738,]       1       0       0
##  [739,]       1       0       0
##  [740,]       1       0       0
##  [741,]       1       0       0
##  [742,]       0       2       0
##  [743,]       1       0       0
##  [744,]       1       0       0
##  [745,]       0       2       0
##  [746,]       0       2       0
##  [747,]       1       0       0
##  [748,]       1       0       0
##  [749,]       1       0       0
##  [750,]       1       0       0
##  [751,]       1       0       0
##  [752,]       0       2       0
##  [753,]       0       0       3
##  [754,]       1       0       0
##  [755,]       1       0       0
##  [756,]       1       0       0
##  [757,]       0       2       0
##  [758,]       0       2       0
##  [759,]       0       2       0
##  [760,]       1       0       0
##  [761,]       1       0       0
##  [762,]       1       0       0
##  [763,]       1       0       0
##  [764,]       0       2       0
##  [765,]       0       2       0
##  [766,]       1       0       0
##  [767,]       1       0       0
##  [768,]       1       0       0
##  [769,]       1       0       0
##  [770,]       1       0       0
##  [771,]       0       2       0
##  [772,]       1       0       0
##  [773,]       1       0       0
##  [774,]       1       0       0
##  [775,]       1       0       0
##  [776,]       1       0       0
##  [777,]       1       0       0
##  [778,]       1       0       0
##  [779,]       1       0       0
##  [780,]       1       0       0
##  [781,]       1       0       0
##  [782,]       1       0       0
##  [783,]       0       2       0
##  [784,]       1       0       0
##  [785,]       0       2       0
##  [786,]       1       0       0
##  [787,]       0       2       0
##  [788,]       0       2       0
##  [789,]       1       0       0
##  [790,]       0       2       0
##  [791,]       1       0       0
##  [792,]       1       0       0
##  [793,]       1       0       0
##  [794,]       1       0       0
##  [795,]       1       0       0
##  [796,]       1       0       0
##  [797,]       1       0       0
##  [798,]       1       0       0
##  [799,]       1       0       0
##  [800,]       1       0       0
##  [801,]       0       2       0
##  [802,]       1       0       0
##  [803,]       1       0       0
##  [804,]       1       0       0
##  [805,]       1       0       0
##  [806,]       1       0       0
##  [807,]       1       0       0
##  [808,]       1       0       0
##  [809,]       1       0       0
##  [810,]       1       0       0
##  [811,]       1       0       0
##  [812,]       0       2       0
##  [813,]       1       0       0
##  [814,]       1       0       0
##  [815,]       1       0       0
##  [816,]       1       0       0
##  [817,]       1       0       0
##  [818,]       1       0       0
##  [819,]       1       0       0
##  [820,]       1       0       0
##  [821,]       1       0       0
##  [822,]       1       0       0
##  [823,]       1       0       0
##  [824,]       1       0       0
##  [825,]       1       0       0
##  [826,]       1       0       0
##  [827,]       1       0       0
##  [828,]       1       0       0
##  [829,]       1       0       0
##  [830,]       1       0       0
##  [831,]       1       0       0
##  [832,]       1       0       0
##  [833,]       1       0       0
##  [834,]       1       0       0
##  [835,]       1       0       0
##  [836,]       1       0       0
##  [837,]       1       0       0
##  [838,]       1       0       0
##  [839,]       0       2       0
##  [840,]       0       2       0
##  [841,]       1       0       0
##  [842,]       1       0       0
##  [843,]       0       2       0
##  [844,]       0       2       0
##  [845,]       1       0       0
##  [846,]       1       0       0
##  [847,]       1       0       0
##  [848,]       1       0       0
##  [849,]       0       2       0
##  [850,]       0       2       0
##  [851,]       1       0       0
##  [852,]       1       0       0
##  [853,]       0       2       0
##  [854,]       1       0       0
##  [855,]       1       0       0
##  [856,]       1       0       0
##  [857,]       1       0       0
##  [858,]       1       0       0
##  [859,]       1       0       0
##  [860,]       1       0       0
##  [861,]       1       0       0
##  [862,]       1       0       0
##  [863,]       1       0       0
##  [864,]       1       0       0
##  [865,]       1       0       0
##  [866,]       1       0       0
##  [867,]       1       0       0
##  [868,]       1       0       0
##  [869,]       0       0       3
##  [870,]       0       0       3
##  [871,]       1       0       0
##  [872,]       1       0       0
##  [873,]       1       0       0
##  [874,]       1       0       0
##  [875,]       1       0       0
##  [876,]       1       0       0
##  [877,]       1       0       0
##  [878,]       1       0       0
##  [879,]       1       0       0
##  [880,]       1       0       0
##  [881,]       1       0       0
##  [882,]       1       0       0
##  [883,]       0       2       0
##  [884,]       1       0       0
##  [885,]       0       2       0
##  [886,]       1       0       0
##  [887,]       1       0       0
##  [888,]       0       2       0
##  [889,]       0       2       0
##  [890,]       0       2       0
##  [891,]       1       0       0
##  [892,]       1       0       0
##  [893,]       0       0       3
##  [894,]       1       0       0
##  [895,]       1       0       0
##  [896,]       1       0       0
##  [897,]       1       0       0
##  [898,]       1       0       0
##  [899,]       1       0       0
##  [900,]       1       0       0
##  [901,]       1       0       0
##  [902,]       0       2       0
##  [903,]       1       0       0
##  [904,]       1       0       0
##  [905,]       1       0       0
##  [906,]       1       0       0
##  [907,]       1       0       0
##  [908,]       0       2       0
##  [909,]       1       0       0
##  [910,]       0       2       0
##  [911,]       1       0       0
##  [912,]       1       0       0
##  [913,]       1       0       0
##  [914,]       1       0       0
##  [915,]       1       0       0
##  [916,]       0       2       0
##  [917,]       1       0       0
##  [918,]       1       0       0
##  [919,]       1       0       0
##  [920,]       0       0       3
##  [921,]       0       2       0
##  [922,]       0       2       0
##  [923,]       1       0       0
##  [924,]       1       0       0
##  [925,]       0       2       0
##  [926,]       1       0       0
##  [927,]       1       0       0
##  [928,]       0       2       0
##  [929,]       1       0       0
##  [930,]       1       0       0
##  [931,]       1       0       0
##  [932,]       1       0       0
##  [933,]       1       0       0
##  [934,]       1       0       0
##  [935,]       0       0       3
##  [936,]       0       2       0
##  [937,]       1       0       0
##  [938,]       0       2       0
##  [939,]       1       0       0
##  [940,]       1       0       0
##  [941,]       1       0       0
##  [942,]       1       0       0
##  [943,]       1       0       0
##  [944,]       0       2       0
##  [945,]       1       0       0
##  [946,]       1       0       0
##  [947,]       1       0       0
##  [948,]       0       0       3
##  [949,]       1       0       0
##  [950,]       1       0       0
##  [951,]       1       0       0
##  [952,]       0       0       3
##  [953,]       1       0       0
##  [954,]       1       0       0
##  [955,]       1       0       0
##  [956,]       1       0       0
##  [957,]       1       0       0
##  [958,]       1       0       0
##  [959,]       1       0       0
##  [960,]       1       0       0
##  [961,]       1       0       0
##  [962,]       1       0       0
##  [963,]       1       0       0
##  [964,]       1       0       0
##  [965,]       0       2       0
##  [966,]       1       0       0
##  [967,]       1       0       0
##  [968,]       1       0       0
##  [969,]       1       0       0
##  [970,]       0       2       0
##  [971,]       1       0       0
##  [972,]       0       2       0
##  [973,]       1       0       0
##  [974,]       1       0       0
##  [975,]       1       0       0
##  [976,]       1       0       0
##  [977,]       1       0       0
##  [978,]       1       0       0
##  [979,]       1       0       0
##  [980,]       1       0       0
##  [981,]       0       2       0
##  [982,]       1       0       0
##  [983,]       1       0       0
##  [984,]       1       0       0
##  [985,]       1       0       0
##  [986,]       1       0       0
##  [987,]       0       2       0
##  [988,]       1       0       0
##  [989,]       1       0       0
##  [990,]       1       0       0
##  [991,]       1       0       0
##  [992,]       1       0       0
##  [993,]       1       0       0
##  [994,]       1       0       0
##  [995,]       1       0       0
##  [996,]       1       0       0
##  [997,]       1       0       0
##  [998,]       1       0       0
##  [999,]       1       0       0
## [1000,]       0       0       3
class_mag2 <- index_1 + index_2 + index_3
class_mag2
##    [1] 1 1 2 1 1 1 1 1 1 1 1 1 1 1 3 1 3 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1
##   [35] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2
##   [69] 1 3 1 1 1 2 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 2 2 1 1 1
##  [103] 1 1 1 1 1 1 3 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1
##  [137] 2 1 1 1 1 1 2 1 1 1 1 1 2 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 2 1 1
##  [171] 1 1 1 1 1 3 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1
##  [205] 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 2
##  [239] 1 1 1 1 2 1 2 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1
##  [273] 1 1 3 1 2 1 1 2 1 1 1 1 1 1 1 1 1 2 2 1 1 1 2 2 3 1 1 1 1 1 1 1 1 1
##  [307] 1 1 1 1 1 2 2 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 2 2 1 1 2 2 1 1 2 1 1
##  [341] 1 1 1 1 1 1 1 1 2 1 1 1 1 3 1 2 2 3 1 1 1 1 2 1 1 1 2 1 1 1 2 2 2 2
##  [375] 1 3 1 2 1 3 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 3 2 1 1 1 2 1 1 1 1
##  [409] 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##  [443] 1 1 2 1 1 2 3 1 1 1 1 1 1 1 1 1 2 1 1 2 2 1 2 1 1 1 1 1 1 1 1 2 1 1
##  [477] 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##  [511] 1 3 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 2 1 1 3 1 1 1 1 1 1 1 2 1 3 1 1 1
##  [545] 1 1 2 1 2 1 1 1 1 1 1 1 1 3 1 1 1 1 1 2 1 1 1 2 1 3 2 1 1 2 1 1 1 1
##  [579] 2 2 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 3 1 1 1 1 1 1 1
##  [613] 1 1 2 1 1 2 1 1 1 1 2 2 1 1 1 1 2 1 1 1 1 1 1 3 1 2 1 1 1 1 2 1 1 1
##  [647] 1 1 3 1 2 1 3 1 1 1 2 1 1 1 1 1 3 2 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1
##  [681] 2 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 1 3 1 2
##  [715] 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 2 1 1
##  [749] 1 1 1 2 3 1 1 1 2 2 2 1 1 1 1 2 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1
##  [783] 2 1 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1
##  [817] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 1 1 1 1 2 2
##  [851] 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 2 1
##  [885] 2 1 1 2 2 2 1 1 3 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 1 1 1 2 1 1
##  [919] 1 3 2 2 1 1 2 1 1 2 1 1 1 1 1 1 3 2 1 2 1 1 1 1 1 2 1 1 1 3 1 1 1 3
##  [953] 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1
##  [987] 2 1 1 1 1 1 1 1 1 1 1 1 1 3
col_var <- brewer.pal(3, "Blues")
plot(quakes_spdf,
     col = col_var[class_mag2],
     cex = 1.4,
     pch = 20)

par(mfrow = c(1, 1))

RgoogleMaps

library(RgoogleMaps)
class(quakes$lat)
## [1] "numeric"
MyMap <- MapBackground(lat = quakes$lat, 
                       lon = quakes$long,
                       zoom = 10)
## [1] "http://maps.google.com/maps/api/staticmap?center=-24.655,176.9&zoom=4&size=640x640&maptype=mobile&format=png32&sensor=true"
## center, zoom:  -24.655 176.9 10
PlotOnStaticMap(MyMap, 
               quakes$lat,
               quakes$long,
               cex = mag_z + 0.3,
               pch = 1,
               col = '#FB6A4A80')

MyMap <- MapBackground(lat = quakes$lat, 
                       lon = quakes$long,
                       zoom = 10,
                       maptype = "satellite")
## [1] "http://maps.google.com/maps/api/staticmap?center=-24.655,176.9&zoom=4&size=640x640&maptype=satellite&format=png32&sensor=true"
## center, zoom:  -24.655 176.9 10
PlotOnStaticMap(MyMap, 
               quakes$lat,
               quakes$long,
               cex = mag_z + 0.3,
               pch = 1,
               col = '#FB6A4A80')

Mapping Lines and Attributes

data(newhaven)
xmin <- bbox(roads)[1, 1]
ymin <- bbox(roads)[2, 1]
xmax <- xmin + diff(bbox(roads)[1, ]) / 2 
# xmax <- bbox(roads)[1, 2]
ymax <- ymin + diff(bbox(roads)[2, ]) / 2 
# ymax <- bbox(roads)[2, 2]
xx <- c(xmin, xmin, xmax, xmax, xmin)
yy <- c(ymin, ymax, ymax, ymin, ymin)
crds <- cbind(xx, yy)
Pl <- Polygon(crds)
Pl
## An object of class "Polygon"
## Slot "labpt":
## [1] 541191.7 160184.0
## 
## Slot "area":
## [1] 352507740
## 
## Slot "hole":
## [1] FALSE
## 
## Slot "ringDir":
## [1] 1
## 
## Slot "coords":
##           xx       yy
##     531806.2 150794.2
##     531806.2 169573.8
## max 550577.1 169573.8
## max 550577.1 150794.2
##     531806.2 150794.2
ID <- "clip"
Pls <- Polygons(list(Pl), ID = ID)
Pls
## An object of class "Polygons"
## Slot "Polygons":
## [[1]]
## An object of class "Polygon"
## Slot "labpt":
## [1] 541191.7 160184.0
## 
## Slot "area":
## [1] 352507740
## 
## Slot "hole":
## [1] FALSE
## 
## Slot "ringDir":
## [1] 1
## 
## Slot "coords":
##           xx       yy
##     531806.2 150794.2
##     531806.2 169573.8
## max 550577.1 169573.8
## max 550577.1 150794.2
##     531806.2 150794.2
## 
## 
## 
## Slot "plotOrder":
## [1] 1
## 
## Slot "labpt":
## [1] 541191.7 160184.0
## 
## Slot "ID":
## [1] "clip"
## 
## Slot "area":
## [1] 352507740
SPls <- SpatialPolygons(list(Pls))
df <- data.frame(value = 1, row.names = ID)
df
##      value
## clip     1
clip.bb <- SpatialPolygonsDataFrame(SPls, df)
roads_tmp <- gIntersection(clip.bb, 
                           roads, 
                           byid = TRUE)
head(names(roads_tmp))
## [1] "clip 2951" "clip 2952" "clip 2959" "clip 2960" "clip 2965" "clip 2972"
tmp <- as.numeric(gsub("clip", "", names(roads_tmp)))
tmp <- data.frame(roads)[tmp, ]
head(tmp)
##      FNODE_ TNODE_ LPOLY_ RPOLY_    LENGTH ROADM_ ROADM_ID  AV_LEGEND
## 2950   1978   1973      2      2  280.9774   2951   160745 LOCAL ROAD
## 2951   1979   1972      2      2  662.1912   2952   160761 LOCAL ROAD
## 2958   1870   1983      2      2  887.6739   2959   227941 LOCAL ROAD
## 2959   1984   1962      2      2  315.7033   2960   160779 LOCAL ROAD
## 2964   1987   1686      2      2 2508.8198   2965   160819 LOCAL ROAD
## 2971   1990   1991      2      2  252.7340   2972   160878 LOCAL ROAD
##      ROARC_COD PHOTRV_FLG QUAD_NO OVRPAS_COD LIMACC_FLG NO_LANES
## 2950       209          0       0          0          0        0
## 2951       209          0       0          0          0        0
## 2958       217          1       0          0          0        0
## 2959       209          0       0          0          0        0
## 2964       209          0       0          0          0        0
## 2971       209          0       0          0          0        0
##       LENGTH_MI DXF_LAYER SPLIT
## 2950 0.05321542       209     0
## 2951 0.12541500       209     0
## 2958 0.16812006       217     0
## 2959 0.05979228       209     0
## 2964 0.47515526       209     0
## 2971 0.04786629       209     0
roads_tmp <- SpatialLinesDataFrame(roads_tmp, 
                                   data = tmp, 
                                   match.ID = FALSE)
par(mfrow = c(1, 3))
plot(roads_tmp)
road_class <- unique(roads_tmp$AV_LEGEND)
shades <- rev(brewer.pal(length(road_class), "Spectral"))
tmp <- roads_tmp$AV_LEGEND
index <- match(tmp, as.vector(road_class))
plot(roads_tmp, col = shades[index], lwd = 3)
plot(roads_tmp, lwd = roads_tmp$LENGTH_MI * 10)

par(mfrow = c(1, 1))